/*
 * @Author: Siogo 你的邮箱
 * @Date: 2025-10-16 15:13:20
 * @LastEditors: Siogo 你的邮箱
 * @LastEditTime: 2025-10-20 11:02:14
 * @FilePath: /frontend/src/api/tb/group.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Page, BasicQuery } from '../model/baseModel';
import { defHttp } from '/@/utils/http/axios';

export interface DeviceInGroup {
  id: string;
  deviceName: string;
}

export interface EntityGroup {
  id?: any;
  name: string;
  description?: string;
  deviceCount?: number;
  createdTime?: number;
  devices?: DeviceInGroup[];
}

export interface DeviceGroupIdPayload {
  id: string;
  entityType: string;
}

export interface DeviceGroupPayload {
  name: string;
  description?: string;
  id?: DeviceGroupIdPayload;
}

export interface DeviceGroupRequest extends DeviceGroupPayload {}

export function getEntityGroupList(params: BasicQuery) {
  return defHttp.get<Page<EntityGroup>>({
    url: '/api/deviceGroups',
    params,
  });
}

export function deleteEntityGroup(deviceGroupId: string) {
  return defHttp.delete<void>({
    url: `/api/deviceGroup/${deviceGroupId}`,
  });
}

export function getDeviceGroupById(deviceGroupId: string) {
  return defHttp.get<EntityGroup>({
    url: `/api/deviceGroup/${deviceGroupId}`,
  });
}

export function saveDeviceGroup(data: DeviceGroupPayload) {
  return defHttp.postJson<EntityGroup>({
    url: '/api/deviceGroup',
    data,
  });
}

export interface AddDeviceToGroupParams {
  deviceGroupId: string;
  deviceIds: any[];
}

export function addDeviceToGroup(data: AddDeviceToGroupParams) {
  return defHttp.postJson<void>({
    url: '/api/deviceGroup/addDevice',
    data,
  });
}

export interface RemoveDeviceFromGroupParams {
  deviceGroupId: string;
  deviceIds: string[];
}

export function removeDeviceFromGroup(data: RemoveDeviceFromGroupParams) {
  return defHttp.postJson<void>({
    url: '/api/deviceGroup/delDevice',
    data,
  });
}
